
#pragma once

#include <stdio.h>


#define CHECKED_OPEN_READ(fileHandle, fileName) \
    if (!result) \
    { \
        fileHandle = fopen(fileName, "rb"); \
        if (!fileHandle) \
        { \
            fprintf(stderr, "error: can't open %s for reading\n", fileName); \
            result = -1; \
        } \
    }

#define CHECKED_OPEN_WRITE(fileHandle, fileName) \
    if (!result) \
    { \
        fileHandle = fopen(fileName, "wb"); \
        if (!fileHandle) \
        { \
            fprintf(stderr, "error: can't open %s for writing\n", fileName); \
            result = -1; \
        } \
    }


#define CHECKED_CLOSE(fileHandle) \
    if (fileHandle) \
    { \
        fclose(fileHandle); \
        fileHandle = NULL; \
    }
